﻿using Edge.Repository.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;

namespace CameraClient.CForm.CameraF
{
    public partial class FormPxsz : Form
    {
        public FormPxsz()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            KeyValService dal = new KeyValService();

            if (radioButton5.Checked == true) { dal.SetConfig("6*4", "PingXian", "radioButton5"); }
            else if (radioButton4.Checked == true) { dal.SetConfig("5*4", "PingXian", "radioButton4"); }
            else if (radioButton3.Checked == true) { dal.SetConfig("5*5", "PingXian", "radioButton3"); }
            else if (radioButton2.Checked == true) { dal.SetConfig("6*5", "PingXian", "radioButton2"); }
            else if (radioButton1.Checked == true) { dal.SetConfig("6*6", "PingXian", "radioButton1"); }
            this.DialogResult = DialogResult.OK;
        }

        private void FormPxsz_Load(object sender, EventArgs e)
        {
            KeyValService dal = new KeyValService();

            string val = dal.GetConfig("PingXian");

            if (string.IsNullOrEmpty(val))
            {
                dal.SetConfig("5*4", "PingXian", "radioButton4");
                radioButton4.Checked = true;
            }
            else
            {
                 if ("radioButton5" == val) { radioButton5.Checked = true; }
                 else if ("radioButton4" == val) { radioButton4.Checked = true; }
                 else if ("radioButton3" == val) { radioButton3.Checked = true; }
                 else if ("radioButton2" == val) { radioButton2.Checked = true; }
                 else if ("radioButton1" == val) { radioButton1.Checked = true; }

            }

            //   radioButton2.Checked = true;
        }
    }
    public static class PingXianHelper
    {

        public static PingXianConfig getPingXianConfig()
        {

            KeyValService dal = new KeyValService();
            string val = dal.GetConfig("PingXian");
            if (string.IsNullOrEmpty(val))
            {
                dal.SetConfig("5*4", "PingXian", "radioButton4");
                val = "radioButton4";
            }

            PingXianConfig pingXian= GetPingXians().FirstOrDefault(F => F.key == val);
            return pingXian;
        }


        public static List<PingXianConfig> GetPingXians()
        {
            List<PingXianConfig> outList = new List<PingXianConfig>();

            outList.Add(new PingXianConfig() { col = 6, row = 4, key = "radioButton5" });
            outList.Add(new PingXianConfig() { col = 5, row = 4, key = "radioButton4" });
            outList.Add(new PingXianConfig() { col = 5, row = 5, key = "radioButton3" });
            outList.Add(new PingXianConfig() { col = 6, row = 5, key = "radioButton2" });
            outList.Add(new PingXianConfig() { col = 6, row = 6, key = "radioButton1" });


            return outList;
        }



    }



    public class PingXianConfig
    {

        public PingXianConfig() { }

        public int col { get; set; }
        public int row { get; set; }
        public string key { get; set; }

    }

}
